package com.rylan.controller;

import com.rylan.entity.User;
import com.rylan.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @author rylan
 * @description
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserRepository userRepository;
    @GetMapping("/findAll/{index}/{limit}")
    public List<User> findAll(@PathVariable("index") int index,@PathVariable("limit") int limit){
        return userRepository.findAll(index,limit);
    }
    @GetMapping("/findById/{id}")
    public User findById(@PathVariable("id") long id){
        return userRepository.findById(id);
    }
    @PutMapping("/update")
    public void update(@RequestBody User user){
        userRepository.update(user);
    }
    @PostMapping("/save")
    public void save(@RequestBody User user){
        userRepository.save(user);
    }
    @DeleteMapping("/deleteById/{id}")
    public void  DeleteById(@PathVariable("id") long id){
        userRepository.deleteById(id);
    }
    @GetMapping("/count")
    public int count(){
        return userRepository.count();
    }

}
